package com.twotiger.and.service;

import java.util.concurrent.ConcurrentHashMap;

import android.content.Context;

import com.twotiger.and.util.PackageUtils;
import com.twotiger.and.util.PreferencesUtils;
import com.twotiger.and.util.StringUtils;

/**
 * 用户Service
 * @Description: TODO(这里描述这个类的作用) 
 * @Author douxy
 * @Date 2015年8月12日 下午3:39:05
 */
public class OtherService {

    private static String GESTURE_OPEN_FLAG = "GESTURE_OPEN_FLAG";
    private static String startCount = "startCount";
    public static String sp_versionname = "sp_versionname";
    private Context mContext;
    private static ConcurrentHashMap<String, Object> cash = new ConcurrentHashMap<String, Object>();
    private static String SharePic = "sharePic";

    public OtherService(Context context) {
        this.mContext = context;
    }

    public String getSharePic() {
        return (String) cash.get(SharePic);
    }

    public void saveSharePic(String sharePic) {
        if (StringUtils.isEmpty(sharePic)) {
            return;
        }
        cash.put(SharePic, sharePic);
    }

    /**
     * 获取手势状态
     * @return
     */
    public boolean gestureIsOpened() {
        return PreferencesUtils.getBoolean(mContext, GESTURE_OPEN_FLAG, true);
    }

    /**
     * 开启手势密码
     */
    public void openGesture() {
        PreferencesUtils.putBoolean(mContext, GESTURE_OPEN_FLAG, true);
    }

    /**
     * 关闭手势
     */
    public void closeGesture() {
        PreferencesUtils.putBoolean(mContext, GESTURE_OPEN_FLAG, false);
    }

    /**
     * 第一次启动
     */
    public boolean isFirstStart() {
        return PreferencesUtils.getInt(mContext, startCount, 0) == 0;
    }
    
    /**
     * 是否版本升级
     * 
     * @param mContext
     * @return true表示升级，false表示没有升级
     */
    public boolean isUpgrade(Context mContext){
        String versionPre = PreferencesUtils.getString(mContext, sp_versionname, null);
        String versionNow = PackageUtils.getAppVersionName(mContext);
        return !versionNow.equals(versionPre);
    }

    /**
     * 标记启动次数
     */
    public void startCount() {
        int c = PreferencesUtils.getInt(mContext, startCount, 1);
        PreferencesUtils.putInt(mContext, startCount, ++c);
    }

}
